﻿Public Class MainForm

    Dim AdminPanelOn As Boolean
    Dim AcademyPanelOn As Boolean
    Dim FEPanelOn As Boolean

    Dim NewVersionMessage As Boolean = False

    'Dim unhangThread = New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf callForm))

    Declare Sub CoFreeUnusedLibraries Lib "ole32" ()

    'Private Sub callForm()
    '    Dim aForm = New Form()

    '    aForm.Height = 10
    '    aForm.Width = 10
    '    aForm.FormBorderStyle = Windows.Forms.FormBorderStyle.None
    '    aForm.ShowInTaskbar = False
    '    aForm.Location = New Point(2000, 2000)
    '    aForm.Visible = False
    '    aForm.Show()
    'End Sub

    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'before even doing this make sure you have an LSC and YPLA user
        '   If SystemInformation.UserDomainName <> "LSC" Then
        ' Windows.Forms.MessageBox.Show("You are not currently on the LSC domain.  Please connect to the LSC domain before attempting to launch The Store", "No LSC Domain", MessageBoxButtons.OK, MessageBoxIcon.Error)
        ' Application.Exit()
        ' Exit Sub
        ' End If


        'unhangThread.start()


        CloseLoadingForm = True
        ShowSplashScreen()

        AdminPanelOn = False
        AcademyPanelOn = False
        FEPanelOn = False

        LogonPic.Image = LogonImages.Images(0)
        Me.Refresh()

        Me.Cursor = Cursors.WaitCursor


        Job("Performing connection...")
        SplashScreen.TheProgress.Value = 30

        ConnectionTest()

        Job("Retrieving global settings...")
        SplashScreen.TheProgress.Value = 50

        LoadGlobalSettingsFromDB()

        Job("Setting up welcome screen...")
        SplashScreen.TheProgress.Value = 70
        
        'Welcome Form Docking to Main Form
        WelcomeForm.MdiParent = Me
        WelcomeForm.Dock = DockStyle.Fill
        WelcomeForm.Show()
        Try
            WelcomeForm.WelcomeBrowser.Navigate(LocationofWelcome)
        Catch ex As Exception
            'the object was disposed
        End Try

        WelcomeForm.ButtonPanel.Visible = False

        Job("Setting up The Store...")
        SplashScreen.TheProgress.Value = 80
        
        'Provider Form Docking to Main Form
        ProvidersForm.MdiParent = Me
        ProvidersForm.Dock = DockStyle.Fill

        'Volumes Form Docking to Main Form
        VolumesForm.MdiParent = Me
        VolumesForm.Dock = DockStyle.Fill

        'Admin Form Docking to Main Form
        AdminForm.MdiParent = Me
        AdminForm.Dock = DockStyle.Fill

        'Academy Form Docking to Main Form
        AcademyForm.MdiParent = Me
        AcademyForm.Dock = DockStyle.Fill

        'FE Form Docking to Main Form
        FEForm.MdiParent = Me
        FEForm.Dock = DockStyle.Fill

        'Model Form Docking to Main Form
        ModelForm.MdiParent = Me
        ModelForm.Dock = DockStyle.Fill

        'Users Form Docking to Main Form
        UsersForm.MdiParent = Me
        UsersForm.Dock = DockStyle.Fill

        ''Admin Provider Form Docking to Main Form
        'AdminProvidersForm.MdiParent = Me
        'AdminProvidersForm.Dock = DockStyle.Fill

        'Periods Form Docking to Main Form
        PeriodsForm.MdiParent = Me
        PeriodsForm.Dock = DockStyle.Fill

        'Budgets Form Docking to Main Form
        BudgetsForm.MdiParent = Me
        BudgetsForm.Dock = DockStyle.Fill

        'Reports Form Docking to Main Form
        ReportsForm.MdiParent = Me
        ReportsForm.Dock = DockStyle.Fill

        'Business Cases Form Docking to Main Form
        CasesForm.MdiParent = Me
        CasesForm.Dock = DockStyle.Fill

        'Settings Form Docking to Main Form
        SettingsForm.MdiParent = Me
        SettingsForm.Dock = DockStyle.Fill

        'Funding Form Docking to Main Form
        FundingForm.MdiParent = Me
        FundingForm.Dock = DockStyle.Fill

        'CaseNotesForm  Docking to Main Form
        CaseNotesForm.MdiParent = Me
        CaseNotesForm.Dock = DockStyle.Fill

        'Reportdesignerform  Docking to Main Form
        ReportDesignerForm.MdiParent = Me
        ReportDesignerForm.Dock = DockStyle.Fill

        'ReportBrowserForm
        ReportBrowserForm.MdiParent = Me
        ReportBrowserForm.Dock = DockStyle.Fill

        'DataEditorForm
        DatacutsForm.MdiParent = Me
        DatacutsForm.Dock = DockStyle.Fill

        'Academy Datasets form
        Acad_DatasetsForm.MdiParent = Me
        Acad_DatasetsForm.Dock = DockStyle.Fill

        'Academy EAG Form
        Acad_EAGForm.MdiParent = Me
        Acad_EAGForm.Dock = DockStyle.Fill

        'new case cration form
        NewCasesCreationForm.MdiParent = Me
        NewCasesCreationForm.Dock = DockStyle.Fill

        'new cases form
        NewCasesForm.MdiParent = Me
        NewCasesForm.Dock = DockStyle.Fill

        'Cases v3
        CasesV3Form.MdiParent = Me
        CasesV3Form.Dock = DockStyle.Fill

        'User Groups Form
        UserGroupsForm.MdiParent = Me
        UserGroupsForm.Dock = DockStyle.Fill

        'Academies Apply Form
        Acad_Apply_Form.MdiParent = Me
        Acad_Apply_Form.Dock = DockStyle.Fill

        'Budgets Form V2
        BudgetsFormV2.MdiParent = Me
        BudgetsFormV2.Dock = DockStyle.Fill

        Job("Retrieving user's full name...")
        SplashScreen.TheProgress.Value = 90

        Me.Cursor = Cursors.Arrow

        LogonPic.Image = LogonImages.Images(1)


        Dim currentADUser As System.DirectoryServices.AccountManagement.UserPrincipal
        currentADUser = System.DirectoryServices.AccountManagement.UserPrincipal.Current

        LogonLabel.Text = "Logged on as (" & GetUserName & ") " & currentADUser.DisplayName
      

        SplashScreen.TheProgress.Value = 100
        LogonUser()

        'set security
        If CurrentUser.Level < 5 Then
            'AdminButton.Enabled = False
            'DatacutsButton.Enabled = False
        End If

        BusinessCaseBut.Enabled = True
        ModellingBut.Enabled = False

        If CurrentVersionNumber = "DEV" Then
            BusinessCaseBut.Enabled = True
            ModellingBut.Enabled = True
        End If

        If UserFormCheck("ModelForm") <> "N" Then
            ModellingBut.Enabled = True
        End If

        Me.Text = "The Store - Version " & CurrentVersionNumber

        If IsDfE Then
            Me.Text = Me.Text & " (DfE)"
        End If

        HideSplashScreen()

        'check if the store is locked
        If CurrentUser.Level <> 5 Then
            If CloseStore() <> "" Then

                MsgBox(CloseStore)
                Application.Exit()

            End If
        End If


        If IsDev Then
            MsgBox("You are connected to the development environment (" & DatabaseName & ")")
            Me.Text = Me.Text & " (Development Environment)"
        End If

        If IsTest Then
            MsgBox("You are connected to the test and training environment (" & DatabaseName & ")")
            Me.Text = Me.Text & " (Test and training environment)"
        End If


    End Sub


    Private Sub HomeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HomeButton.Click
        AdminPanelOn = False
        AcademyPanelOn = False
        FEPanelOn = False

        ShowForm(WelcomeForm)
        WelcomeForm.WelcomeBrowser.Navigate(LocationofWelcome)

    End Sub

    Private Sub ShowForm(ByVal FormName As Form)
       

        HideForms()

        FormName.Show()
    End Sub

    Private Sub HideForms()

        'Hide all forms
        If AdminPanelOn = False Then
            AdminPanel.Visible = False
        End If

        If AcademyPanelOn = False Then
            AcademyPanel.Visible = False
        End If

        If FEPanelOn = False Then
            FEPanel.Visible = False
        End If

        WelcomeForm.Hide()
        ProvidersForm.Hide()
        AdminForm.Hide()
        ModelForm.Hide()
        UsersForm.Hide()
        'AdminProvidersForm.Hide()
        BudgetsForm.Hide()
        ' ReportViewForm.Hide()
        ReportViewerForm.Hide()
        SettingsForm.Hide()
        CasesForm.Hide()
        FundingForm.Hide()
        DatacutsForm.Hide()
        RenameDatacutForm.Hide()
        PeriodsForm.Hide()
        AcademyForm.Hide()
        Acad_DatasetsForm.Hide()
        Acad_EAGForm.Hide()
        NewCasesForm.Hide()
        NewCasesCreationForm.Hide()
        UserGroupsForm.Hide()
        Acad_Apply_Form.Hide()


        'handel the Volumes and Report Form differently
        VolumesForm.Close()
        ReportsForm.Close()
        StageForm.Close()
        CaseNotesForm.Close()
        ReportDesignerForm.Close()
        ReportBrowserForm.Close()
        BudgetsFormV2.Close()
        Acad_DatasetsFormV2.Close()
        ApplyCustomPatternsForm.Close()
        Acad_Apply_FormV2.Close()
        AdminProvidersFormV2.Close()
        ExcelExportForm.Close()
        CasesV3Form.Close()


    End Sub

    Private Sub ProvidersButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProvidersButton.Click
        ShowLoadingForm()

        Me.Cursor = Cursors.WaitCursor



        AdminPanelOn = False
        AcademyPanelOn = False
        FEPanelOn = False

        ShowForm(ProvidersForm)


        Me.Cursor = Cursors.Default


        HideLoadingForm()

    End Sub

    Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click


        Application.Exit()

    End Sub


    Private Sub ReportsButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportsButton.Click

        AdminPanelOn = False
        AdminPanel.Visible = False

        AcademyPanelOn = False
        AcademyPanel.Visible = False

        FEPanelOn = False
        FEPanel.Visible = False

        Me.Cursor = Cursors.WaitCursor

        VolumesForm.Close()
        ReportBrowserForm.Close()

        HideForms()


        ReportsForm.MdiParent = Me
        ReportsForm.Dock = DockStyle.Fill
        ReportsForm.LoadCustomReports()

        ReportsForm.Show()

        Me.Cursor = Cursors.Default
    End Sub

    Private Sub AdminButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AdminButton.Click

        If UserFormCheck(Me.Name) = "N" Then
            MessageBox.Show("Currently you do not have permission to access the Admin section." & vbNewLine & _
                            "Contact TheStore.EFA@education.gsi.gov.uk if you need access.", Me.Name & " Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        ShowLoadingForm()
        MainPanel.Visible = False
        AdminPanel.Visible = True
        AdminPanelOn = True
        AcademyPanelOn = False
        FEPanelOn = False
        ShowForm(AdminForm)

        HideLoadingForm()

    End Sub

    Private Sub AdminUserBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AdminUserBut.Click

        If UserFormCheck("UsersForm") = "N" Then
            MessageBox.Show("Currently you do not have permission to access this form." & vbNewLine & _
                            "Contact TheStore.EFA@education.gsi.gov.uk if you need access.", "Academy Datasets Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        AdminPanelOn = True
        ShowForm(UsersForm)
    End Sub

    'Private Sub AdminProvidersBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AdminProvidersBut.Click

    '    If UserFormCheck("AdminProvidersForm") = "N" Then
    '        MessageBox.Show("Currently you do not have permission to access this form." & vbNewLine & _
    '                        "Contact TheStore.EFA@education.gsi.gov.uk if you need access.", "Academy Datasets Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    '        Exit Sub
    '    End If

    '    Me.Cursor = Cursors.WaitCursor
    '    AdminPanelOn = True
    '    ShowForm(AdminProvidersForm)
    '    Me.Cursor = Cursors.Default
    'End Sub

    Private Sub AdminBudgetsBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AdminBudgetsBut.Click

        If UserFormCheck("BudgetsForm") = "N" Then
            MessageBox.Show("Currently you do not have permission to access this form." & vbNewLine & _
                            "Contact TheStore.EFA@education.gsi.gov.uk if you need access.", "Academy Datasets Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        AdminPanelOn = True
        ShowForm(BudgetsForm)
    End Sub

    Private Sub MainForm_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Job("Exiting, please wait...")
        AddActivity(CurrentUser.Name, "User logged off", 0, "")

        WelcomeForm.WelcomeBrowser.Navigate("about:blank")
        WelcomeForm.WelcomeBrowser.Dispose()

        System.Windows.Forms.Application.DoEvents()
        CoFreeUnusedLibraries()
    End Sub

    Private Sub CheckCloseStore_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim TheMessage As String

        TheMessage = CloseStore()

        If TheMessage <> "" Then
            AdminPanelOn = False
            AdminPanel.Visible = False

            AcademyPanelOn = False
            AcademyPanel.Visible = False

            FEPanelOn = False
            FEPanel.Visible = False

            MainPanel.Visible = True

            'CheckCloseStore.Enabled = False
            TheMessageBox.Text = TheMessage
            'Countdown.Enabled = True

            ClosePanel.Visible = True
        End If

        'while I'm here check to see if there are any jobs at the moment.  if not make status ready.. also check to see if there is a new version

        If Not IsFormOpen(LoadingForm) Then
            Job("Ready")
        End If


        Dim TheData As DataView
        Dim Sql As String

        Sql = "Select * from Global_Settings_Upgrade"

        TheData = LoadDataView(Sql)

        'do a version check

        'check to see if this is a development environment


        If VersionNumber <> TheData(0).Item("Version_Number").ToString Then

            If NewVersionMessage = False Then
                TheData = Nothing
                NewVersionMessage = True
                MessageBox.Show("There is a new version of The Store available.  It is recommended that you exit The Store and relaunch it for the updates to take effect.  You will be reminded of this again in 10 minutes.", _
                                    "New version available", MessageBoxButtons.OK, MessageBoxIcon.Information)
                NewVersionMessage = False
            End If

        End If

        TheData = Nothing


        'If Countdown.Enabled Then
        'Job("The Store has been closed...")
        'End If
    End Sub

    Private Sub Countdown_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim TheMessage As String


        CountDownLabel.Text = CountDownLabel.Text - 1

        If CountDownLabel.Text <= 0 Then
            'Countdown.Enabled = False

            'Check for the last time if you should close
            TheMessage = CloseStore()

            If TheMessage <> "" Then
                If CurrentUser.Level <> 5 Then
                    Me.Close()
                End If
            Else
                'Countdown.Enabled = False
                'CheckCloseStore.Enabled = True
                ClosePanel.Visible = False
            End If

        End If
    End Sub

    Private Sub SettingsButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SettingsButton.Click

        If UserFormCheck("SettingsForm") = "N" Then
            MessageBox.Show("Currently you do not have permission to access this form." & vbNewLine & _
                            "Contact TheStore.EFA@education.gsi.gov.uk if you need access.", "Academy Datasets Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        AdminPanelOn = True
        ShowForm(SettingsForm)
    End Sub

    Private Sub ModellingBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ModellingBut.Click
        AcademyPanelOn = False
        AcademyPanel.Visible = False

        AdminPanelOn = False
        FEPanelOn = True
        ShowForm(ModelForm)

    End Sub

    Private Sub BusinessCaseBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BusinessCaseBut.Click
        AdminPanelOn = False
        AcademyPanelOn = False
        FEPanelOn = True

        ShowLoadingForm()

        ShowForm(CasesForm)

        HideLoadingForm()

    End Sub

    Private Sub AllocBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AllocBut.Click
        AdminPanelOn = True
        ShowForm(FundingForm)
    End Sub

    Private Sub PleaseWaitBG_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
        '   LoadingForm.Show()


        ' While 1 = 1
        ' LoadingForm.Refresh()
        ' If PleaseWaitBG.CancellationPending Then
        'LoadingForm.Close()
        'e.Cancel = True
        'Exit Sub
        'End If
        'End While


    End Sub

    Private Sub SplashBG_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)


        '  SplashScreen.Show()

        '  While 1 = 1
        ' SplashScreen.Refresh()
        ' If SplashBG.CancellationPending Then
        'SplashScreen.Close()
        'e.Cancel = True
        'Exit Sub
        'End If
        'End While


    End Sub

    Private Sub DatacutsButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DatacutsButton.Click

        AdminPanelOn = False
        AcademyPanelOn = False
        FEPanelOn = True


        ShowLoadingForm()

        ShowForm(DatacutsForm)

        HideLoadingForm()

    End Sub


    Private Sub CCMButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CCMButton.Click

        ReportsMenu.Show(CCMButton, New System.Drawing.Point(0, CCMButton.Height))

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        AdminPanelOn = False
        AcademyPanelOn = False
        FEPanelOn = False
        MainPanel.Visible = True
        ShowForm(WelcomeForm)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        If UserFormCheck("PeriodsForm") = "N" Then
            MessageBox.Show("Currently you do not have permission to access this form." & vbNewLine & _
                            "Contact TheStore.EFA@education.gsi.gov.uk if you need access.", "Academy Datasets Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        AdminPanelOn = True
        ShowForm(PeriodsForm)
    End Sub

    Private Sub AcadmiesButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AcadmiesButton.Click
        'You shall not pass!

        If UserFormCheck("AcademyForm") = "N" Then
            MessageBox.Show("Currently you do not have permission to access the Academies section." & vbNewLine & _
                            "Contact TheStore.EFA@education.gsi.gov.uk if you need access.", "Academies Section Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        'If Not HasAccess(AcademyForm) Then
        '    MessageBox.Show("You currently do not have access to the Academy Section.  The Academy Section is currently in a testing phase and only a selection of people have access for the moment.  If you need access to this section please contact TheStore.EFA@education.gsi.gov.uk", "Access Denied", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        '    Exit Sub
        'End If

        ShowLoadingForm()
        MainPanel.Visible = False
        AcademyPanel.Visible = True
        AdminPanelOn = False
        FEPanelOn = False
        AcademyPanelOn = True
        ShowForm(AcademyForm)

        HideLoadingForm()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        AdminPanelOn = False
        AcademyPanelOn = False
        FEPanelOn = False
        MainPanel.Visible = True
        ShowForm(WelcomeForm)
    End Sub

    Private Sub DatasetsButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DatasetsButton.Click

        If UserFormCheck("Acad_DataSetsForm") = "N" Then
            MessageBox.Show("Currently you do not have permission to access this form." & vbNewLine & _
                            "Contact TheStore.EFA@education.gsi.gov.uk if you need access.", "Academy Datasets Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        AdminPanelOn = False
        AcademyPanelOn = True
        FEPanelOn = False
        ShowForm(Acad_DatasetsForm)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        ShowLoadingForm()
        MainPanel.Visible = False
        FEPanel.Visible = True
        AdminPanelOn = False
        FEPanelOn = True
        AcademyPanelOn = False
        ShowForm(FEForm)

        HideLoadingForm()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        AdminPanelOn = False
        AcademyPanelOn = False
        FEPanelOn = False
        MainPanel.Visible = True
        ShowForm(WelcomeForm)
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        MessageBox.Show("This section has been locked until further notice.", "Section Locked", MessageBoxButtons.OK, MessageBoxIcon.Stop)

        'AdminPanelOn = False
        'AcademyPanelOn = True
        'FEPanelOn = False
        'ShowForm(Acad_EAGForm)
    End Sub

    Private Sub CreatePaymentFilesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreatePaymentFilesToolStripMenuItem.Click

        If UserFormCheck("CCMDialog") <> "W" Then
            MessageBox.Show("Currently you do not have permission to access this form." & vbNewLine & _
                            "Contact TheStore.EFA@education.gsi.gov.uk if you need access.", "CCMDialog Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        With CCMDialog
            .TheTabs.SelectedIndex = 0
            .Backbut.Enabled = False
            .NextBut.Enabled = True
            .RegionBar.Value = 0
            .UPINBar.Value = 0
            .ShowDialog()

        End With
    End Sub

    Private Sub FreezePaymentsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FreezePaymentsToolStripMenuItem.Click

        If UserFormCheck("FreezePaymentsForm") <> "W" Then
            MessageBox.Show("Currently you do not have permission to access this form." & vbNewLine & _
                            "Contact TheStore.EFA@education.gsi.gov.uk if you need access.", "FreezePaymentsForm Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        With FreezePaymentsForm
            .ShowDialog()
        End With
    End Sub

    Private Sub KathyBut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KathyBut.Click
        KathysMenu.Show(KathyBut, New System.Drawing.Point(0, KathyBut.Height))
    End Sub

    Private Sub CaseCreationToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CaseCreationToolStripMenuItem.Click
        ShowForm(NewCasesCreationForm)



    End Sub

    Private Sub CasesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CasesToolStripMenuItem.Click
        ShowForm(NewCasesForm)

    End Sub

    Private Sub KathysMenu_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles KathysMenu.Opening
        If CurrentUser.Level <> 5 Then
            CaseCreationToolStripMenuItem.Enabled = False
        Else
            CaseCreationToolStripMenuItem.Enabled = True
        End If
    End Sub


    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

        If UserFormCheck("UserGroupsForm") = "N" Then
            MessageBox.Show("Currently you do not have permission to access this form." & vbNewLine & _
                            "Contact TheStore.EFA@education.gsi.gov.uk if you need access.", "Academy Datasets Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        ShowForm(UserGroupsForm)

    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click

        If UserFormCheck("Acad_ApplyForm") <> "W" Then
            MessageBox.Show("Currently you do not have permission to access this form." & vbNewLine & _
                            "Contact TheStore.EFA@education.gsi.gov.uk if you need access.", "Academy Apply Allocations Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        ShowForm(Acad_Apply_Form)
    End Sub

    Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        ShowForm(CasesV3Form)


    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click

        HideForms()

        BudgetsFormV2.MdiParent = Me
        BudgetsFormV2.Dock = DockStyle.Fill
        BudgetsFormV2.Show()

    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        If UserFormCheck("Acad_DataSetsForm") = "N" Then
            MessageBox.Show("Currently you do not have permission to access this form." & vbNewLine & _
                            "Contact TheStore.EFA@education.gsi.gov.uk if you need access.", "Academy Datasets Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        HideForms()


        Acad_DatasetsFormV2.MdiParent = Me
        Acad_DatasetsFormV2.Dock = DockStyle.Fill
        Acad_DatasetsFormV2.Show()

    End Sub

    Private Sub ReportsMenu_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ReportsMenu.Opening

        FreezePaymentsToolStripMenuItem.Visible = False

        


    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click

        If UserFormCheck("Acad_ApplyForm") <> "W" Then
            MessageBox.Show("Currently you do not have permission to access this form." & vbNewLine & _
                            "Contact TheStore.EFA@education.gsi.gov.uk if you need access.", "Academy Apply Allocations Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If

        HideForms()
        Acad_Apply_FormV2.MdiParent = Me
        Acad_Apply_FormV2.Dock = DockStyle.Fill
        Acad_Apply_FormV2.Show()

    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click

        If UserFormCheck("AdminProvidersForm") = "N" Then
            MessageBox.Show("Currently you do not have permission to access this form." & vbNewLine & _
                            "Contact TheStore.EFA@education.gsi.gov.uk if you need access.", "Academy Datasets Access", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If


        AdminPanelOn = True

        HideForms()

        AdminProvidersFormV2.MdiParent = Me
        AdminProvidersFormV2.Dock = DockStyle.Fill
        AdminProvidersFormV2.Show()


    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        HideForms()

        CasesV3Form.MdiParent = Me
        CasesV3Form.Dock = DockStyle.Fill
        CasesV3Form.Show()

    End Sub

   
End Class
